/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wave;

import base.*;

/**
 *
 * @author Tue
 */
public class WaveProcessor extends Thread{
    private SynchronousQueue<Wave> waveQueue;
    private WaveInterpreter wi;
    private WaveHeadParser parserUnit;
    public WaveProcessor(WaveInterpreter wi){
        this.wi = wi;
        waveQueue = wi.getWaveQueue();        
    }
    @Override
    public void run(){
        System.out.println("\t[Wave Processor] running...");
        while(true){
            Wave w = waveQueue.dequeue();
            Utilities.WIPrint(w.toString() + ": " + w.getWaveEnv());
            Thread thread1 = new WaveHeadParser(wi, w);

            if(Utilities.MULTI_THREAD){
                thread1.start();
                w = waveQueue.dequeue();
                Utilities.WIPrint(w.toString() + ": " + w.getWaveEnv());
                Thread thread2 = new WaveHeadParser(wi, w);
                thread2.start();
                w = waveQueue.dequeue();
                Utilities.WIPrint(w.toString() + ": " + w.getWaveEnv());
                Thread thread3 = new WaveHeadParser(wi, w);
                thread3.start();
                try {
                    thread1.join();
                    thread2.join();
                    thread3.join();
                } catch (InterruptedException interupEx){
                    interupEx.printStackTrace();
                }
            } else {
                thread1.run();
            }
        }
    }
}
